/**
 * Definition for a binary tree node.
 * function TreeNode(val, left, right) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.left = (left===undefined ? null : left)
 *     this.right = (right===undefined ? null : right)
 * }
 */
/**
 * 递归，快
 * @param {number[]} nums
 * @return {TreeNode}
 */
var sortedArrayToBST = function (nums) {
    return sortedArrayLevel(nums, 0, nums.length - 1)
};

function sortedArrayLevel(nums, left, right) {
    if (left > right) return null
    let mid = ~~((left + right) / 2),
        node = new TreeNode(nums[mid]);

    node.left = sortedArrayLevel(nums, left, mid - 1);
    node.right = sortedArrayLevel(nums, mid + 1, right);

    return node
}